package leetcode;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

/**
 * create by duanx 2022/2/7
 *@classname: Test3
 *@author: duanx
 *@date: 2022/2/7 9:22
 **/
public class Test8 {

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str;
        try{
            while(!(str=reader.readLine()).isEmpty()){
                Map<Integer,Integer> map = new HashMap<>(256);
                int n = Integer.parseInt(str);
                if(n>11111111||n<0){
                    throw new  IllegalArgumentException();
                }
                for(int i =0;i<n;i++){
                    String input = reader.readLine();
                    String[] inputs = input.split(" ");
                    int key = Integer.parseInt(inputs[0]);
                    int in = Integer.parseInt(inputs[1]);
                    if (in>100000|| in< 1){
                        throw new  IllegalArgumentException();
                    }
                    Integer value = map.get(key);
                    if (value!=null){
                        in = value+in;
                    }
                    map.put(key,in);
                }
                Object[] entries = map.keySet().toArray();
                Arrays.sort(entries);
                for (Object key :entries){
                    System.out.println(key+" "+map.get(key));
                }
            }
        }catch (Exception e){
            System.out.println(e.getMessage());
        }

    }


}
